package com.ruoyi.admin.controller;

import com.ruoyi.admin.service.ICreditRecordService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.CreditRecord;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 积分记录Controller
 * 
 * @author xukai
 * @date 2024-12-22
 */
@RestController
@RequestMapping("/credit/credit")
public class CreditRecordController extends BaseController
{
    @Autowired
    private ICreditRecordService creditRecordService;

    /**
     * 查询积分记录列表
     */
    //@PreAuthorize("@ss.hasPermi('credit:credit:list')")
    @GetMapping("/list")
    public TableDataInfo list(CreditRecord creditRecord)
    {
        startPage();
        List<CreditRecord> list = creditRecordService.selectCreditRecordList(creditRecord);
        return getDataTable(list);
    }

    /**
     * 导出积分记录列表
     */
    //@PreAuthorize("@ss.hasPermi('credit:credit:export')")
    @Log(title = "积分记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CreditRecord creditRecord)
    {
        List<CreditRecord> list = creditRecordService.selectCreditRecordList(creditRecord);
        ExcelUtil<CreditRecord> util = new ExcelUtil<CreditRecord>(CreditRecord.class);
        util.exportExcel(response, list, "积分记录数据");
    }

    /**
     * 获取积分记录详细信息
     */
    //@PreAuthorize("@ss.hasPermi('credit:credit:query')")
    @GetMapping(value = "/{type}")
    public AjaxResult getInfo(@PathVariable("type") String type)
    {
        return success(creditRecordService.selectCreditRecordByType(type));
    }

    /**
     * 新增积分记录
     */
    //@PreAuthorize("@ss.hasPermi('credit:credit:add')")
    @Log(title = "积分记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CreditRecord creditRecord)
    {
        return toAjax(creditRecordService.insertCreditRecord(creditRecord));
    }

    /**
     * 修改积分记录
     */
    //@PreAuthorize("@ss.hasPermi('credit:credit:edit')")
    @Log(title = "积分记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CreditRecord creditRecord)
    {
        return toAjax(creditRecordService.updateCreditRecord(creditRecord));
    }

    /**
     * 删除积分记录
     */
    //@PreAuthorize("@ss.hasPermi('credit:credit:remove')")
    @Log(title = "积分记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{types}")
    public AjaxResult remove(@PathVariable String[] types)
    {
        return toAjax(creditRecordService.deleteCreditRecordByTypes(types));
    }
}
